﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApplication1.Class.Bean;

namespace WpfApplication1.GestionBug
{
    /// <summary>
    /// Logique d'interaction pour PageGestion.xaml
    /// </summary>
    public partial class PageGestion : Window
    {
        private ClassBug bug;
        private ClassPersonne personne;

        public ClassPersonne Personne
        {
            get { return personne; }
            set { personne = value; }
        }
        public ClassBug Bug
        {
            get { return bug; }
            set { bug = value; }
        }

        
        public PageGestion(ClassBug bug)
        {
            InitializeComponent();
            this.Bug = bug;

            if (ClassCurrentUserSingleton.Instance.Role == ClassPersonne.ROLE_CHEFPROJET)
            {
                this.ListEtat.Visibility = System.Windows.Visibility.Visible;

            }
            List<SearchField> list = new List<SearchField>();
            list.Add(new SearchField("IdBug", bug.Id, SearchField.EGAL_A));
            List<ClassCommentaires> commentaires = ClassCommentaires.Search(list);


            Binding source = new Binding();
            source.Source = commentaires;
            this.ListCommentaires.SetBinding(DataContextProperty, source);
            this.ListCommentaires.DisplayMemberPath = "ShowCommentaire";

            this.TextBlockDescription.Text += bug.DateEmission.ToShortDateString();
            this.TextBlockEmmeteur.Text += ClassPersonne.Read(bug.IdEmmeteur, new ClassPersonne()).Nom;
            this.TextBlockEnvironnement.Text += bug.Environnement;
            this.TextBlockEtat.Text += bug.Etat;
            this.TextBlockNom.Text += bug.Nom;
            this.TextBlockPriorite.Text += bug.Priorite;
            this.TextBlockResponsable.Text += ClassPersonne.Read(bug.IdResponsable, new ClassPersonne()).Nom;
            this.TextBlockType.Text += bug.Type;

           
        }

        private void AjoutComm_Click_1(object sender, RoutedEventArgs e)
        {
            ClassCommentaires commentaire = new ClassCommentaires();
            commentaire.Commentaire = TextCommentaire.Text;
            commentaire.DateComm = DateTime.Now;
            commentaire.IdBug = this.bug.Id;
            commentaire.IdEmmeteur = ClassCurrentUserSingleton.Instance.Id;
            ClassCommentaires.SaveOrUpdate(commentaire);

            List<SearchField> list = new List<SearchField>();
            list.Add(new SearchField("IdBug", bug.Id, SearchField.EGAL_A));
            List<ClassCommentaires> commentaires = ClassCommentaires.Search(list);


            Binding source = new Binding();
            source.Source = commentaires;
            this.ListCommentaires.SetBinding(DataContextProperty, source);
            this.ListCommentaires.DisplayMemberPath = "ShowCommentaire";
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            if (ClassCurrentUserSingleton.Instance.Role == ClassPersonne.ROLE_CHEFPROJET)
            {

            }

        }
    }
}
